var initialState = {
  count: 0,
  count1: 0,
  lists: {},
  carts:[],
};

function reducer(state = initialState, action) {
  switch (action.type) {
    case "INCREASE":
      // return {count: state.count + 1}//现在这种模式是直接修改数据操作，不是纯函数
      return Object.assign({}, state, { count: state.count + 1 });
    case "DECREASE":
      // return {count1: state.count1 - 1}
      return Object.assign({}, state, { count1: state.count1 - 1 });
    case "GETLISTS":
      return Object.assign({},state,{lists: action.data})
      //这里action.data而不是state.data是因为：这个data是type为"GETLISTS"下面传过来的data，而increase和decrease只有type，没有data的传递。所以是state.data
    case "ADDTOCART":
      return {
        ...state,
        carts:[...state.carts,action.data],
      }
    default:
      return state;
  }
}

export default reducer;
